package com.lagou.dao;

import com.lagou.io.Resources;
import com.lagou.pojo.User;
import com.lagou.sqlSession.SqlSession;
import com.lagou.sqlSession.SqlSessionFactory;
import com.lagou.sqlSession.SqlSessionFactoryBulider;

import java.io.InputStream;
import java.util.List;

/**
 * @author <a href="mailto:zhouyong@cqyyt.com">zy</a>
 * @version 1.0
 * @date 2020/12/7 15:59
 */
public class UserDaoImpl implements UserDao{
    @Override
    public List<User> selectList() throws Exception {
        InputStream inputStream = Resources.getResourceAsSteam("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBulider().builid(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //调通
        String statementid1 = "user.selectList";
        List<User> objects = sqlSession.selectList(statementid1);
        for (int i = 0; i < objects.size(); i++) {
            System.out.println(objects.get(i));
        }

        return objects;
    }

    @Override
    public User selectOne(User user) throws Exception {

        InputStream inputStream = Resources.getResourceAsSteam("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBulider().builid(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //调通
        String statementid = "user.selectOne";
        User user1 = sqlSession.selectOne(statementid, user);
        System.out.println(user1);
        return user1;
    }
}
